<%--
  Created by IntelliJ IDEA.
  User: d11yu
  Date: 2022/4/14
  Time: 11:37
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<div id="page_nav">
    <c:if test="${page.pn>1}">
        <button class="page-unselected first-page" onclick="location.href='${page.urlAction}&pn=1'">&nbsp;</button>
        <button class="page-unselected previous-page" onclick="location.href='${page.urlAction}&pn=${page.pn-1}'">
            &nbsp;
        </button>
    </c:if>
    <c:choose>
        <%--情况 1:如果总页码小于等于6的情况，页码的范围是：1-总页码--%>
        <c:when test="${page.pt <= 6}">
            <c:set scope="request" var="begin" value="1"/>
            <c:set scope="request" var="end" value="${page.pt}"/>
        </c:when>
        <%--情况2:总页码大于6的情况--%>
        <c:when test="${page.pt > 6}">
            <c:choose>
                <c:when test="${page.pn <= 3}">
                    <c:set scope="request" var="begin" value="1"/>
                    <c:set scope="request" var="end" value="${page.pt}"/>
                </c:when>
                <c:when test="${page.pn >= page.pt - 5}">
                    <c:set scope="request" var="begin" value="${page.pt - 5}"/>
                    <c:set scope="request" var="end" value="${page.pt}"/>
                </c:when>
                <c:otherwise>
                    <c:set scope="request" var="begin" value="${page.pn - 2}"/>
                    <c:set scope="request" var="end" value="${page.pn + 2}"/>
                </c:otherwise>
            </c:choose>
        </c:when>
    </c:choose>
    <c:forEach begin="${begin}" end="${end}" var="i">
        <c:if test="${i == page.pn}">
            <button class="page-selected">${i}</button>
        </c:if>
        <c:if test="${i != page.pn}">
            <button class="page-unselected" onclick="location.href='${page.urlAction}&pn=${i}'">${i}</button>
        </c:if>
    </c:forEach>
    <c:if test="${page.pn<page.pt}">
        <button class="page-unselected next-page" onclick="location.href='${page.urlAction}&pn=${page.pn + 1}'">&nbsp;</button>
        <button class="page-unselected last-page" onclick="location.href='${page.urlAction}&pn=${page.pt}'">&nbsp;</button>
    </c:if>
    <span class="page-text">共${page.pt}页、${page.ect}条记录，跳转到第<input value="${page.pn}" name="pn" id="pn_input"/>页</span>
    <button class="page-unselected" style="width: 50px" id="goto">确定</button>
</div>
<script type="text/javascript">
    $(function () {
        $("#goto").click(function () {
            location.href = "${page.urlAction}&pn=" + $("#pn_input").val();
            return false;
        });
    });
</script>